package com.wealth.scsj.b_app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.bean.ShopSwitchListBean;

import java.util.List;

import q.rorbin.badgeview.Badge;

/**
 * 当前账号页面 店铺切换adapter
 */
public class AccountShopListAdapter extends RecyclerView.Adapter<AccountShopListAdapter.MyViewHolder> {

    private Context mContext;
    private List<ShopSwitchListBean> mList;
    private LayoutInflater mInflater;
    SwitchOnClick switchOnClick;

    public AccountShopListAdapter(Context context, List<ShopSwitchListBean> data) {
        this.mContext = context;
        this.mList = data;
        mInflater = LayoutInflater.from(context);
    }

    public void setSwitchOnClick(SwitchOnClick switchOnClick) {
        this.switchOnClick = switchOnClick;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_account_shop_list, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

//        holder.badge.setBadgeTextSize(12, true);
//        holder.badge.stroke(0xffffffff,2,true);
//        holder.badge.setBadgeGravity(Gravity.CENTER);
//        holder.badge.setBadgeNumber(Integer.parseInt("1"));
//        holder.badge.setBadgeBackgroundColor(0xffe5473b);//top_bar_color
        holder.mShopNameTv.setText(mList.get(position).getShop_name());
        if(mList.get(position).getShop_select()==1){
            holder.mShopSwitchTv.setBackgroundResource(R.drawable.shop_switch_select_bg);
            holder.mShopSwitchTv.setText("已绑定");
            holder.mShopSwitchTv.setTextColor(mContext.getResources().getColor(R.color.notice_text_color));
            holder.mShopSwitchTv.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.shop_switch_select_icon,0,0,0);
        }else if(mList.get(position).getShop_select()==2){
            holder.mShopSwitchTv.setBackgroundResource(R.drawable.shop_switch_unselect_bg);
            holder.mShopSwitchTv.setText("切换");
            holder.mShopSwitchTv.setTextColor(mContext.getResources().getColor(R.color.store_setting_red));
            holder.mShopSwitchTv.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.shop_switch_icon,0,0,0);
        }

        holder.mShopSwitchTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchOnClick.onclick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView mShopNameTv;
        public TextView mShopSwitchTv;
        public ImageView mShopLogoIv;
        public ImageView mShopMessageRemindIv;
        Badge badge;


        public MyViewHolder(View itemView) {
            super(itemView);
            mShopNameTv =  itemView.findViewById(R.id.shop_name_tv);
            mShopSwitchTv =  itemView.findViewById(R.id.shop_switch_tv);
            mShopLogoIv =itemView.findViewById(R.id.shop_logo_iv);
//            mShopMessageRemindIv=itemView.findViewById(R.id.shop_message_remind_iv);
//            badge =new QBadgeView(mContext).bindTarget(itemView.findViewById(R.id.shop_message_remind_iv));
        }
    }

    public interface SwitchOnClick{
        void onclick(int position);
    }
}
